package com.river.springbootdemo.algorithm;

import java.util.List;

public class BinarySearch {
    public static Integer binarySearch(List<Integer> list, Integer item) {
        Integer low = 0;
        Integer high = list.size();
        while (low <= high) {
            Integer mid = (low + high) / 2;
            Integer currentValue = list.get(mid);
            if (currentValue.equals(item)) {
                return mid;
            }
            if (currentValue > item) {
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return null;
    }
}
